package com.zl.cms.service;

import com.zl.basic.model.Pager;
import com.zl.cms.dao.IKeywordDao;
import com.zl.cms.model.Keyword;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-3-16 Time: 下午7:43
 */
@Service("keywordService")
public class KeywordService implements IKeywordService {
  private IKeywordDao keywordDao;

  public IKeywordDao getKeywordDao() {
    return keywordDao;
  }

  @Inject
  public void setKeywordDao(IKeywordDao keywordDao) {
    this.keywordDao = keywordDao;
  }

  @Override
  public void addOrUpdate(String name) {
    keywordDao.addOrUpdate(name);
  }

  @Override
  public List<Keyword> getKeywordByTimes(int num) {
    List<Keyword> ks = keywordDao.findUseKeyword();
    List<Keyword> kks = new ArrayList<>();
    for (Keyword k : ks) {
      if (k.getTimes() >= num)
        kks.add(k);
      // ks中关键字是倒序排列,有一个不大于num后面不用考虑
      else
        break;
    }
    return kks;
  }

  @Override
  public List<Keyword> getMaxTimesKeyword(int num) {
    List<Keyword> ks = keywordDao.findUseKeyword();
    List<Keyword> kks = new ArrayList<>();
    if (ks.size() <= num) return ks;
    for (int i = 0; i < num; i++) {
      kks.add(ks.get(i));
    }
    return kks;
  }

  @Override
  public Pager<Keyword> findNoUseKeyword() {
    return keywordDao.findNoUseKeyword();
  }

  @Override
  public void clearNoUseKeyword() {
    keywordDao.clearNoUseKeyword();
  }

  @Override
  public List<Keyword> listKeywordByCon(String con) {
    return keywordDao.listKeywordByCon(con);
  }

  @Override
  public List<Keyword> findUseKeyword() {
    return keywordDao.findUseKeyword();
  }

	@Override
	public List<String> listKeywordstringByCon(String con) {
		return keywordDao.listKeywordStringByCon(con);
	}
}
